<?php 
/***
 * 类型属性管理控制器
 */
class TypeAttrController extends AuthController{
	private $model;
//	private static $tid;
	public function __init(){
		parent::__init();
		$this->model = K('TypeAttr');
	}
	
	
	public function index(){
		//获取tid
		$Type_tid = Q('get.tid');
//		$Type_tid=$this->tid = Q('get.tid');
		$data = $this->model->where("Type_tid={$Type_tid}")->all();
		$this->assign('data',$data);
		$this->display();
	}
	
	/**
	 * 添加属性
	 */
	public function add(){
		
		if(IS_POST){
			$Type_tid = Q('get.tid');
			//处理tavalue
			$tavalue = str_replace('|', ',', Q('post.tavalue'));
			$data = array(
				'taname'  => Q('post.taname'),
				'tavalue' => $tavalue,
				'class'   => Q('post.class'),
				'Type_tid'=> $Type_tid
			);
			
			if(!$this->model->addTypeAttr($data)) $this->error($this->model->error);
			$this->success('添加成功');
		}
		$this->display();
	}
	
	/***
	 * 修改属性
	 */
	public function edit(){
		$taid = Q('get.taid');
		if(IS_POST){
			
			if(!$this->model->edit($taid)) $this->error($this->model->error);
			//获取tid
			$data = $this->model->where("taid={$taid}")->find();
			$tid = $data['Type_tid'];
			$this->success('编辑成功',U("Admin/TypeAttr/index/tid/{$tid}"));
			
		}
		//分配变量
		$data = $this->model->where("taid={$taid}")->find();
		$this->assign('data',$data);
		$this->display();
		
	}
	
	/**
	 * 删除
	 */
	public function delete(){
		$taid = Q('get.taid');
//		$this->model->where("taid={$taid}")->delete();
		//获取tid
		$data = $this->model->where("taid={$taid}")->find();
		$tid = $data['Type_tid'];
		$this->success('删除成功',U("Admin/TypeAttr/index/tid/{$tid}"));
		
	}
	
	
	
	
	
	
}
























 ?>